﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace praticetwo
{
    class StudentDBHeper
    {
        public static void SeachStudent()
        {
            string conn = "server=.;database=School;uid=sa;Pwd=lsy6796159..";
            SqlConnection sqlconn = new SqlConnection(conn);
            sqlconn.Open();
            var sql = "select * from StudentInfo";
            SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
            var sqldr = sqlcmd.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", "StudentID", "StudentName", "StudentSex", "StudentAge", "StudentScore");
            while (sqldr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", sqldr["StudentID"], sqldr["StudentName"], sqldr["StudentSex"], sqldr["StudentAge"], sqldr["StudentScore"]);

            }
            sqlconn.Close();
        }

        private readonly string conn = "server=.;database=School;uid=sa;Pwd=lsy6796159..";
        private readonly string sqlconn = "select * from StudentInfo";
        public void SeachStudent1()
        {
            SqlDataAdapter sqlsad = new SqlDataAdapter(sqlconn, conn);
            DataTable dt = new DataTable();
            sqlsad.Fill(dt);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", "StudentID", "StudentName", "StudentSex", "StudentAge", "StudentScore");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", dt.Rows[i]["StudentID"], dt.Rows[i]["StudentName"], dt.Rows[i]["StudentSex"], dt.Rows[i]["StudentAge"], dt.Rows[i]["StudentScore"]);
            }
        }
    }
}
